package com.voute.Utils;

import com.voute.Consts.Constants;
import com.voute.Model.Bean.BaseBean;

import rx.Subscriber;

/**
 * 共同的地方处理Rxjava
 * Created by liukanshan on 2017/1/1.
 */

public abstract class CommonSubscriber<T extends BaseBean> extends Subscriber<T> {

    public abstract void onSuccess(T response);

    public abstract void onFailure(BaseBean response);

    @Override
    public void onError(Throwable e) {
        BaseBean error=new BaseBean();
        error.setStatus(Constants.NET_ERROR);
        error.setMsg("网络链接错误,请重试");
        onFailure(error);
    }

    @Override
    public void onNext(T t) {
        if (t.getStatus() == Constants.REQUEST_SUCCESS) {
            onSuccess(t);
        } else {
            onFailure(t);
        }
    }

    @Override
    public void onCompleted() {

    }
}
